//
//  MessageManageViewController.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/12.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MessageManageViewController.h"
#import "MessageViewController.h"
#import "FriendViewController.h"

#import "XXPageTabView.h"

@interface MessageManageViewController()<XXPageTabViewDelegate>

@property (strong, nonatomic) UIButton *leftNavBtn;

@property (strong, nonatomic) UIButton *rightNavBtn; 

/**
 pageTableView
 */
@property (nonatomic , strong) XXPageTabView *pageTabView;
/**
 被转让的猪
 */
@property (nonatomic , strong) MessageViewController *messageVC;
/**
 转让记录
 */
@property (nonatomic , strong) FriendViewController *friendVC;


@end


@implementation MessageManageViewController

#pragma mark - view life cycle

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self setUpView];
    [self initNav];
}


#pragma mark - init method

- (void)initNav {
    
    self.view.backgroundColor = KWhiteColor;

    self.baseNavView.hidden = YES;

    [self.view addSubview:self.leftNavBtn];
    [self.view addSubview:self.rightNavBtn];
    
}


- (void)setUpView {
    [self initView];
    [self initLayout];
    [self initAction];
    [self initData];
}


- (void)initView {
    
    [self addChildViewController:self.messageVC];
    [self addChildViewController:self.friendVC];
    
    [self.view addSubview:self.pageTabView];
}


- (void) initLayout {
    
    {
        CGFloat topHeight = TJ_ISIphoneX ?34 :20;
        self.leftNavBtn.frame = CGRectMake(15, topHeight, 44,  TJ_NavBarHeight-topHeight);
    }
    
    {
        self.rightNavBtn.frame = _leftNavBtn.frame;
        _rightNavBtn.width = 44;
        _rightNavBtn.mj_x = KScreenWidth - _rightNavBtn.width -5;
    }

    
    [self.pageTabView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(TJ_StatusBarHeight);
    }];
    
}

- (void) initAction {
    
}

- (void)initData {
    
}


#pragma mark - delegate
- (void)scrollToLast:(id)sender {
    [self.pageTabView setSelectedTabIndexWithAnimation:self.pageTabView.selectedTabIndex-1];
}

- (void)scrollToNext:(id)sender {
    [self.pageTabView setSelectedTabIndexWithAnimation:self.pageTabView.selectedTabIndex+1];
}


#pragma mark - target action

- (void)transferManagerTapped {
    
}



#pragma mark - private method

#pragma mark - getter and setter

- (UIButton *)leftNavBtn{
    if (!_leftNavBtn) {
        
        _leftNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_leftNavBtn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
        _leftNavBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        @weakify(self);
        _leftNavBtn.tapBlock = ^{
            @strongify(self);
            [self.navigationController popViewControllerAnimated:YES];
        };
    }
    
    return _leftNavBtn;
}


- (UIButton *)rightNavBtn{
    if (!_rightNavBtn) {
        
        _rightNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rightNavBtn setImage:[UIImage imageNamed:@"message_clear"] forState:UIControlStateNormal];
        
        @weakify(self);
        _rightNavBtn.tapBlock = ^{
            @strongify(self);
            [self.navigationController popViewControllerAnimated:YES];
        };
    }
    return _rightNavBtn;
}


- (XXPageTabView *)pageTabView {
    if (!_pageTabView) {
        _pageTabView = [[XXPageTabView alloc] initWithChildControllers:self.childViewControllers childTitles:@[@"平台通知",@"好友消息"]];
        _pageTabView.delegate = self;
        _pageTabView.indicatorStyle = XXPageTabIndicatorStyleFollowText;//跟随文本变化长度
        _pageTabView.titleStyle = XXPageTabTitleStyleBlend;//渐变
        _pageTabView.selectedTabIndex = 0;
        _pageTabView.tabSize = CGSizeMake(185, 38);
        _pageTabView.separatorColor = [UIColor clearColor];
        _pageTabView.tabItemFont = mMediumFont(18);
        _pageTabView.indicatorHeight = 0;
        _pageTabView.bodyBounces = NO;
        _pageTabView.selectedColor = [UIColor colorWithHexString:@"#333333"];
        _pageTabView.unSelectedColor = [UIColor colorWithHexString:@"#979797"];
        _pageTabView.tabBackgroundColor = [UIColor clearColor];
        _pageTabView.bodyBackgroundColor = [UIColor clearColor];
    }
    return _pageTabView;
}


- (FriendViewController *)friendVC {
    if (!_friendVC) {
        _friendVC = [[FriendViewController alloc] init];
    }
    return _friendVC;
}


- (MessageViewController *)messageVC {
    if (!_messageVC) {
        _messageVC = [[MessageViewController alloc] init];
    }
    return _messageVC;
}


@end
